const { mysql } = require("../qcloud");

module.exports = async (ctx) => {
  // const books = await mysql("books").select("*");   //单表查询
  //添加分页
  const {page}=ctx.request.query
  const size=5;
  //多表联查
  const books = await mysql("books")
    .select("books.*","cSessionInfo.user_info")
    .join('cSessionInfo','books.openid','cSessionInfo.open_id')
    .limit(size)
    .offset(Number(page)*size)
    .orderBy('books.id','desc');
  ctx.state.data={
  list:books.map(v=>{
   const info=JSON.parse(v.user_info)
   return Object.assign({},v,{
     user_info:{
     nickName:info.nickName
     }
   })
  }),
  }
};
